<?php
//300s
require_once __DIR__ . '/../../autoload.php';
use  src\DataBase;
$roomID=$_GET['roomID'];
if(is_file("./".$roomID.".json") && (time()-filemtime("./".$roomID.".json") < 10)) {  
   header("location:choiceCourse.php?roomID=".$roomID);
}else{
	$db= new DataBase\DataBaseOperate('139.196.124.180','school','user1','Mcx857264','utf8');
	$selectResult=$db->select('room','*',array('roomName'=>$roomID));
	$roomCourse=explode(",",$selectResult['courseName']);
	$courseJson=array();
	foreach($roomCourse as $key=>$value){
		$courseJson[]=array('0'=>($key+1),'1'=>$value);
	}
	$output=json_encode($courseJson);
	$file=file_put_contents("./".$roomID.".json", $output);
    	
	header("location:choiceCourse.php?roomID=".$roomID);
}
?>